package com.lzj.hdfs2hbase;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //拆分字符串
        String[] ss = value.toString().replaceAll("[^\\w‘\\-\\s]+", "").split("\\s+");

        //开始拆分
        for (int i = 0; i < ss.length; i++) {
            Text outputKey = new Text(ss[i]);
            context.write(outputKey, new IntWritable(1));
        }
    }

}